//
//  PriceView.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/1.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "PriceView.h"

@interface PriceView ()

@property (nonatomic, strong) UILabel *priceSymbol;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *productSymbol;
@property (nonatomic, strong) UILabel *periodsLabel;


@end

@implementation PriceView


- (instancetype)init {
    
    self = [super init];
    if (self) {
        [self.priceSymbol mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.mas_equalTo(self);
            make.height.mas_equalTo(10);
        }];
        [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self);
            make.height.mas_equalTo(14);
            make.left.mas_equalTo(self.priceSymbol.mas_right).offset(1);
        }];
        [self.productSymbol mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self);
            make.height.mas_equalTo(12);
            make.left.mas_equalTo(self.priceLabel.mas_right).offset(2);
        }];
        [self.periodsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self);
            make.height.mas_equalTo(12);
            make.left.mas_equalTo(self.productSymbol.mas_right).offset(2);
        }];
    }
    return self;
}



/**
 价格铭牌展示信息

 @param price 价格
 @param periods 期数
 @param priceShowType 期数展示类型
 */
- (void)updateInfoPrice:(NSString *)price periods:(NSString *)periods priceShowType:(PriceShowType)priceShowType {
    
    self.priceLabel.text = price;
    if (periods.length != 0) {
        self.periodsLabel.text = [NSString stringWithFormat:@"%@期",periods];
        self.productSymbol.hidden = NO;
    }else{
        self.productSymbol.hidden = YES;
    }
    
    if (priceShowType == PriceShowTypeRedPeriods) {
        self.productSymbol.textColor = HexColor(0xFF2244);
        self.periodsLabel.textColor = HexColor(0xFF2244);
    }else if (priceShowType == PriceShowTypeGrayPeriods) {
        self.productSymbol.textColor = HexColor(0x3F3F3F);
        self.periodsLabel.textColor = HexColor(0x3F3F3F);
    }else if (priceShowType == PriceShowTypeGoodsDetail){
        self.priceLabel.font = [UIFont systemFontOfSize:18];
        self.productSymbol.textColor = HexColor(0x3F3F3F);
        self.periodsLabel.textColor = HexColor(0x3F3F3F);
        self.periodsLabel.font = [UIFont systemFontOfSize:12];
        [self.priceLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self);
            make.height.mas_equalTo(18);
            make.left.mas_equalTo(self.priceSymbol.mas_right).offset(1);
        }];
        
    }
}



- (UILabel *)priceSymbol {
    
    if (!_priceSymbol) {
        _priceSymbol = [[UILabel alloc] init];
        _priceSymbol.textColor = HexColor(0xFF2244);
        _priceSymbol.font = [UIFont systemFontOfSize:10];
        _priceSymbol.text = @"¥";
        
        [self addSubview:_priceSymbol];
    }
    return _priceSymbol;
}

- (UILabel *)priceLabel {
    
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = HexColor(0xFF2244);
        _priceLabel.font = [UIFont systemFontOfSize:14];
        
        [self addSubview:_priceLabel];
    }
    return _priceLabel;
}

- (UILabel *)productSymbol {
    
    if (!_productSymbol) {
        _productSymbol = [[UILabel alloc] init];
        _productSymbol.textColor = HexColor(0xFF2244);
        _productSymbol.font = [UIFont systemFontOfSize:12];
        _productSymbol.text = @"x";
        
        [self addSubview:_productSymbol];
    }
    return _productSymbol;
}

- (UILabel *)periodsLabel {
    
    if (!_periodsLabel) {
        _periodsLabel = [[UILabel alloc] init];
        _periodsLabel.textColor = HexColor(0xFF2244);
        _periodsLabel.font = [UIFont systemFontOfSize:12];
        
        [self addSubview:_periodsLabel];
    }
    return _periodsLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
